import pytest

from src.application.user.enums import LangCode
from src.application.user.exceptions import UserIdAlreadyExist
from src.application.user.use_cases.change_user_language import ChangeUserLang, ChangeUserLangHandler
from src.application.user.use_cases.create_user import CreateUser, CreateUserHandler
from src.domain.user.aggregates import UserAggregate
from src.domain.user.value_objects import TelegramUserId, UserId
from tests.mocks.uow import UnitOfWorkMock
from tests.mocks.user_repo import UserRepoMock


async def test_change_user_language(
    uow: UnitOfWorkMock,
    user_repo: UserRepoMock,
) -> None:
    user_id = UserId(0)
    user_tg_id = TelegramUserId(1413248651)
    user = UserAggregate(id=user_id, tg_id=user_tg_id, username="web2py")
    user_repo.users[user.tg_id] = user

    command = ChangeUserLang(tg_user_id=user_tg_id.value, lang_code="ru")
    handler = ChangeUserLangHandler(uow=uow)

    await handler(command=command)

    assert user.lang_code == LangCode("ru")
    assert uow.commit_status is True
    assert uow.rollback_status is False
